package ai.loa.utility;

import java.util.HashMap;
import java.util.Map;

import ai.loa.ai.Mossa;

public final class ConstantValues {
	public static final int[][][][][][] MOVES;
	public static final Map<Integer, Mossa> MOVES_CACHE;
	public static final int[][] CENTRALIZATION_VALUES = {
			{ -80, -25, -20, -20, -20, -20, -25, -80 },
			{ -25, 10, 10, 10, 10, 10, 10, -25 },
			{ -20, 10, 25, 25, 25, 25, 10, -20 },
			{ -20, 10, 25, 50, 50, 25, 10, -20 },
			{ -20, 10, 25, 50, 50, 25, 10, -20 },
			{ -20, 10, 25, 25, 25, 25, 10, -20 },
			{ -25, 10, 10, 10, 10, 10, 10, -25 },
			{ -80, -25, -20, -20, -20, -20, -25, -80 } };
	public static final int[] MINIMAL_DISTANCES = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
			10, 12, 14 };

	public static final int[][] FRAME_VALUES = 
		  { { 6, 3, 3, 3, 3, 3, 3, 6 },
			{ 3, 2, 2, 2, 2, 2, 2, 3 }, 
			{ 3, 2, 1, 1, 1, 1, 2, 3 },
			{ 3, 2, 1, 0, 0, 1, 2, 3 }, 
			{ 3, 2, 1, 0, 0, 1, 2, 3 },
			{ 3, 2, 1, 1, 1, 1, 2, 3 },
			{ 3, 2, 2, 2, 2, 2, 2, 3 },
			{ 6, 3, 3, 3, 3, 3, 3, 6 } };

	public static final double[][] COM_POSITIONS = {
			{ 30, 30, 30, 30, 30, 30, 30, 30 },
			{ 30, 20, 20, 20, 20, 20, 20, 30 },
			{ 30, 20, 10, 10, 10, 10, 20, 30 },
			{ 30, 20, 10, 0, 0, 10, 20, 30 }, { 30, 20, 10, 0, 0, 10, 20, 30 },
			{ 30, 20, 10, 10, 10, 10, 20, 30 },
			{ 30, 20, 20, 20, 20, 20, 20, 30 },
			{ 30, 30, 30, 30, 30, 30, 30, 30 } };
	// { { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 },
	// { 0.5, 1, 1, 1, 1, 1, 1, 0.5 },
	// { 0.5, 1, -0.5, -0.5, -0.5, -0.5, 1, 0.5 },
	// { 0.5, 1, -0.5, -1, -1, -0.5, 1, 0.5 },
	// { 0.5, 1, -0.5, -1, -1, -0.5, 1, 0.5 },
	// { 0.5, 1, -0.5, -0.5, -0.5, -0.5, 1, 0.5 },
	// { 0.5, 1, 1, 1, 1, 1, 1, 0.5 },
	// { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 } };

	// TODO va calcolato per bene
	public static final int MAX_CONCENTRATION = 1;
	// la centralizzazione massima va calcolata in base al numero di pezzi in
	// gioco
	public static final int[] MAX_CENTRALIZATION = { 50, 100, 150, 200, 225,
			250, 275, 300, 325, 350, 375, 400 };
	// TODO va calcolato per bene
	public static final int[] MAX_QUAD = { 1, 1, 1, 2, 4, 4, 4, 6, 6, 6, 8, 8 };

	public static final int MAX_RECT = 48;

	public static final double[][][][][] MOBILITY = new double[2][8][8][8][8];

	static {
		// Preparazione della cache,
		// inizializzazione array della cache
		MOVES_CACHE = new HashMap<Integer, Mossa>(1126, 1);
		// player, mangia, sourceX, sourceY, destX, destY
		MOVES = new int[2][2][8][8][8][8];
		for (int i = 0; i < 2; i++) {
			for (int n = 0; n < 2; n++) {
				for (int j = 0; j < 8; j++) {
					for (int k = 0; k < 8; k++) {
						for (int h = 0; h < 8; h++) {
							for (int l = 0; l < 8; l++) {
								MOVES[i][n][j][k][h][l] = l + 8 * h + 8 * 8 * k
										+ 8 * 8 * 8 * j + 8 * 8 * 8 * 8 * n + 8
										* 8 * 8 * 8 * 2 * i;
								Mossa m = new Mossa();
								m.player = (byte) i;
								if (n == 0)
									m.mangia = false;
								else
									m.mangia = true;
								m.cellStartX = j;
								m.cellStartY = k;
								m.cellDestX = h;
								m.cellDestY = l;

								MOVES_CACHE.put(MOVES[i][n][j][k][h][l], m);
							}
						}
					}
				}
			}
		}
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 8; j++) {
				for (int k = 0; k < 8; k++) {
					for (int l = 0; l < 8; l++) {
						for (int z = 0; z < 8; z++) {
							double val = 1;
							if (i == 1)
								val *= 2;
							if (ConstantValues.FRAME_VALUES[j][k] < ConstantValues.FRAME_VALUES[l][z]) {
								val *= 0.5;
							}
							MOBILITY[i][j][k][l][z]=val;
						}

					}

				}

			}

		}
	}

}
